package com.voja.mrvica2.fragment;

import java.util.ArrayList;

import com.voja.mrvica2.Entry;
import com.voja.mrvica2.Index;
import com.voja.mrvica2.R;
import com.voja.mrvica2.adapter.EntryAdapter;
import com.voja.mrvica2.listener.ItemClickListener;
import com.voja.mrvica2.listener.ItemScrollListener;

import android.app.ListFragment;
import android.os.Bundle;
import android.view.View;
import android.widget.ListView;

public class MiddleFragment extends ListFragment {
    public static final String ITEM_IDENTIFIER = "item_id";
    
    private ArrayList<Entry> entries;
    private ListView list;
    private ItemScrollListener onScroll;
    private ItemClickListener  onClick;
    public static Index activity;
    
    public MiddleFragment() {}
    
    public void setParams(ArrayList<Entry> entries, Index activity) {
        this.entries  = entries;
        MiddleFragment.activity = activity;
        
        onScroll = new ItemScrollListener(activity);
        onClick  = new ItemClickListener(activity);
    }
    
    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        
        list = getListView();
        
        list.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
        EntryAdapter adapter = new EntryAdapter(getActivity(), R.layout.entry_item, entries);
        setListAdapter(adapter);
        
        list.setOnScrollListener(onScroll);
        list.setOnItemClickListener(onClick);
    }
    
    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
    }
}
